<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tbody td {
            width: 80px;
            height: 80px;
        }
        #tft {
            width: 76px;
            height: 76px;
            margin-top: 10px;
            border-radius: 50%;
            background-image: url('./slfn.png');
            background-size: contain;
            cursor: move;
            position: absolute;
            /* 盒子阴影，x方向，y方向，模糊程度，颜色 */
            /* box-shadow: 5px 5px 10px #333; */
        }
    </style>
</head>
<body>
    <table border="1">
        <tbody class="tbody">
            <tr>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </tbody>
    </table>
    <div id="tft"></div>
    <script>
        // 按下鼠标，获取坐标的偏移量
        tft.onmousedown = function() {
            var x = event.offsetX;
            var y = event.offsetY;
            tft.style.boxShadow = '5px 5px 10px #333';
            // 在拖拽时，鼠标移动是以鼠标按下为前提的，所以移动的代码要卸载按下的代码内部
            // 移动鼠标，光标带着div移动，在移动过程中，两者保持相对静止
            document.onmousemove = function () {
                // console.log(event);
                // 修改tft的坐标，使它移动
                tft.style.left = (event.clientX-x) + 'px'
                tft.style.top = (event.clientY-y) + 'px'
            }
        }

        // 松开鼠标，不再修改坐标
        tft.onmouseup = function() {
            document.onmousemove = null;
            tft.style.boxShadow = 'none';
        }
    </script>
</body>
</html>